<template>

  <el-container style="min-height: calc(100vh - 70px);">
    <el-main>
      <div class="teacher">
        <div class="app-table">
          <div class="app-body">
            <div class="app-search">
              <el-form :inline="true" class="demo-form-inline" v-model="form">
                <el-form-item label="姓名">
                  <el-input placeholder="请输入姓名" v-model="form.name" @keyup.enter="searchEnter"></el-input>
                  <!-- <el-config-provider :locale="locale">
                    <el-date-picker v-model="form.time" type="date" placeholder="请选择日期" :size="size" />
                  </el-config-provider> -->

                </el-form-item>
                <!-- <el-form-item label="人员工号">
                  <el-input placeholder="请输入人员工号" v-model="form.teacherNumber" @keyup.enter="searchEnter"></el-input>
                </el-form-item> -->
                <el-form-item>
                  <el-button class="serach_btn" type="primary" plain @click="onSubmit">搜索</el-button>
                </el-form-item>
                <el-form-item>
                  <el-button class="export_btn" type="primary" plain v-loading.fullscreen.lock="fullscreenLoading"
                    @click="exportHandle">导出报表</el-button>
                </el-form-item>
              </el-form>
            </div>
            <el-table :data="list" size="default" style="width: 100%;" :row-class-name="tableRowClassName">
              <el-table-column prop="id" label="序号" width="60" />
              <el-table-column prop="userName" label="留言人" width="160" />
              <el-table-column prop="createdAt" label="发布时间" width="160" />
              <el-table-column prop="content" label="内容" />
              <el-table-column label="操作" width="100px">
                <template #default="scope">
                  <!-- <el-button class="edit_btn" type="success" @click="editApp(scope.row)">编辑</el-button> -->
                  <el-button class="del_btn" type="danger" @click="deleteApp(scope.row.id)">删除</el-button>
                </template>
              </el-table-column>

              <template v-slot:empty>
                <el-empty description="暂无数据"></el-empty>
              </template>
            </el-table>
            <el-config-provider :locale="locale">
              <el-pagination :total="total" :page-size="limit" :page-sizes="[5, 10, 20, 30, 40, 50, 100]"
                layout="total, sizes, prev, pager, next, jumper" @size-change="changePageSize"
                @current-change="changeCurrentPage">
              </el-pagination>
            </el-config-provider>
          </div>
          <bottomView />
        </div>
      </div>
    </el-main>
  </el-container>
</template>

<script>
import bottomView from "@/components/bottom.vue";
import { ElConfigProvider, ElMessageBox, ElMessage, ElLoading } from "element-plus";
import zhCn from "element-plus/lib/locale/lang/zh-cn";
import { httpService } from "@/utils/httpService";
import { Picture as IconPicture } from "@element-plus/icons-vue";
import { getCurrentInstance } from "vue";
import { decrypt } from "@/utils/dateFormat";


export default {
  name: "BaseTeacherList",

  data() {
    return {
      type: 0,
      title: "",
      page: 0,
      pageSize: 10,
      total: 0,
      limit: 10,
      list: [],
      flagId: '',
      schoolNames: [],
      form: {
        name: "",
        teacherNumber: "",
        time: "",
      },
      fullscreenLoading: false,
      selectData: {},
      mobileNumber: '',
    };
  },
  components: {
    IconPicture,
    ElConfigProvider,
    ElMessageBox,
    ElMessage,
    bottomView, ElLoading,
  },
  watch: {
    '$route.query.type'(newVal) {
      alert(newVal)
      console.log(newVal);
      // this.type = newVal;
      // 根据需要执行其他操作，比如更新视图或发起请求  
    }
  },
  setup() {
    const instance = getCurrentInstance()
    let schoolNames = instance.appContext.config.globalProperties.$schoolNames
    console.log("schoolNames", schoolNames)
    return {
      locale: zhCn,
      schoolNames: schoolNames
    }
  },
  mounted() {
    this.getMessageList();
  },
  watch: {
  },
  methods: {
    searchEnter: function (e) {
      console.log(e);
      // 使用 which 和 keyCode 属性来解决兼容问题
      var keyCode = window.event ? e.keyCode : e.which;
      var val = e.target.value;
      if (keyCode == 13 && val) {
        this.getMessageList();
      }
    },
    add() {
      this.$refs.addBaseTeacherView.title = "添加"
    },
    editApp(obj) {
      this.$refs.editBaseTeacherView.title = "修改信息"
    },

    deleteApp(id) {
      ElMessageBox.confirm("确定要删除本条记录吗？", "提醒", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          httpService("/javaApi/baseMessages/deleteById", "id=" + id, "post").then(
            (data) => {
              if (data.code == 200) {
                ElMessage.success("删除成功");
                this.getMessageList();
              } else {
                ElMessage.error(data.message);
              }
            }
          );
        })
        .catch(() => { });
    },


    onSubmit() {
      this.getMessageList();
    },
    // 每页记录数改变，size：回调参数，表示当前选中的“每页条数”
    changePageSize(size) {
      this.pageSize = size;
      this.limit = size;

      this.getMessageList();
    },

    // 改变页码，page：回调参数，表示当前选中的“页码”
    changeCurrentPage(page) {
      this.page = page;
      this.getMessageList();
    },
    exportHandle() {
      this.fullscreenLoading = true
      httpService(
        "/javaApi/baseMessages/exportExcel", {}, "get"
      ).then((data) => {
        this.fullscreenLoading = false
        window.open(data.message, "_blank")
      });
    },
    getMessageList() {
      httpService(
        "/javaApi/baseMessages/myList/" + this.page + "/" + this.pageSize,
        {
          userName: this.form.name,
          // createdAt: this.form.time ? this.form.time : ''
        },
        "get"
      ).then((res) => {
        const data = res.object
        if (data.list) {
          data.list.map(item => item.createdAt = item.createdAt.slice(0, 10))
        }
        this.list = data.list;
        this.total = data.total;
        this.pageCount = data.pages;
      });
    },

  },
};
</script>

<style scoped>
.el-main {
  padding: 0px;
  text-align: left
}

.teacher-content {
  width: 100%;
}

.app-table {
  background: #eff3f5;
  padding: 5px 10px 10px;
}

.app-separator {
  /* padding-top: 10px; */
  /* padding-bottom: 20px; */
  padding-left: 10px;
}

.app-body {
  background: white;
  padding: 10px 20px 10px 20px;
  margin-bottom: 10px;
  min-height: calc(100vh - 188px);
}

.el-table .warning-row {
  --el-table-tr-bg-color: var(--el-color-warning-lighter);
}

.el-table .success-row {
  --el-table-tr-bg-color: var(--el-color-success-lighter);
}

.el-pagination {
  text-align: center;
  margin-top: 10px;
}

.serach_btn {
  background-color: #007EFF;
  color: #fff;
  border-radius: 8px;
  border: none;
}

.export_btn {
  background-color: #00c78c;
  color: #fff;
  border-radius: 8px;
  border: none;
}

.add_btn {
  background-color: #00c78c;
  color: #fff;
  border-radius: 8px;
  border: none;
}

.edit_btn {
  background-color: #fff;
  color: #00c78c;
  border: none;
}

.del_btn {
  background-color: #fff;
  color: #FF0000;
  border: none;
}

.face_btn {
  background-color: #fff;
  color: #ff8400;
  border: none;
}

.retire_btn {
  background-color: #fff;
  color: #007EFF;
  border: none;
}
</style>
